import { ref, UnwrapRef, Ref } from '@vue/composition-api';

export function useState<T>(defaultVal: T): [Ref<UnwrapRef<T>>, (newVal: UnwrapRef<T>) => void] {
    const state = ref(defaultVal);
    const setState = (newVal: UnwrapRef<T>) => {
        state.value = newVal;
    };
    return [state, setState];
}
// export function useState<T = any>(defaultVal?: T): [Ref<UnwrapRef<T> | undefined>, (newVal: UnwrapRef<T>) => void] {
//     const state = ref(defaultVal);
//     const setState = (newVal: UnwrapRef<T>) => {
//         state.value = newVal;
//     };
//     return [state, setState];
// }
